package liportest.ability;


import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.Message;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.WithStateMachine;
import org.springframework.stereotype.Component;

@Component
@WithStateMachine(name = "abilityStateMachine")
@Slf4j
public class AbilityStateListenerImpl {

    @OnTransition(source = "WRITED",target = "UNAPPROVE")
    public void submitApprove(Message<AbilityChangeEvent> message) {
        final AbilityModel abilityModel = (AbilityModel) message.getHeaders().get("ability");
        abilityModel.setAbilityStatus(AbilityStatus.UNAPPROVE);
        log.info("Ability status changed to {}", message.getHeaders());
    }

    @OnTransition(source = "UNAPPROVE",target = "UNPUBLISHED")
    public void approvePass(Message<AbilityChangeEvent> message) {
        final AbilityModel abilityModel = (AbilityModel) message.getHeaders().get("ability");
        abilityModel.setAbilityStatus(AbilityStatus.UNPUBLISHED);
        log.info("Ability status changed to {}", message.getHeaders());
    }


}
